package cn.apthink.satoken;

import cn.apthink.controller.BaseResult;
import cn.apthink.controller.ResponseEnum;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException;
import lombok.extern.slf4j.Slf4j;

//David: 改用Solon统一异常处理GeneralExceptionInterceptor
@Slf4j
public class SaTokenExceptionHandler {
	public final static BaseResult handlerException(Throwable e) {
		log.debug("=>satoken authentication error: " + e.getMessage());
		if (e instanceof NotLoginException) {
			return BaseResult.error(ResponseEnum.ErrorNoLogin, "未登录");
		}
		if (e instanceof NotPermissionException) {
			return BaseResult.error(ResponseEnum.ErrorNoPermission, e.getMessage());
		}
		return BaseResult.error(ResponseEnum.ErrorUnknown, e.getMessage());
	}

}
